package com.yang.controller;

import com.yang.service.RegisterService;
import org.jboss.logging.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Controller
public class RegisterConteroller {

    private static Logger logger = Logger.getLogger(RegisterConteroller.class);

    @Resource
    RegisterService registerService;

    /**
     * 获取验证码
     * @param emil
     * @return
     */
    @RequestMapping(produces = "application/json;charset=UTF-8",value = "getCode",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> getCode (String emil){
        Map<String,Object> map = new HashMap<String,Object>();
        if(emil == null || emil.equals("")){
            map.put("info","QQmail is null");
            logger.error("QQ邮箱不能为空");
            return map;
        }
        map = registerService.getCode(emil);
        return map;
    }

    /**
     * 注册
     * @param QQEmil
     * @param userName
     * @param password
     * @param code
     * @return
     */
    @RequestMapping(produces = "application/json;charset=UTF-8", value = "register", method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> register (String QQEmil, String userName, String password, String code){
        Map<String,Object> map = new HashMap<String, Object>();
        if(QQEmil==null || userName == null||password==null||code==null||QQEmil.equals("")||
        userName.equals("")||code.equals("")||code.equals("")){
            map.put("info","输入存在空，请填写完整！");
            logger.error("输入存在空！");
            return map;
        }
        map = registerService.register(QQEmil,userName,password,code);
        return map;
    }
}
